<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<title>tb_member分页</title>
<div class="lay-box">
    <div id="toolbar">
        <div class="input-group" style="float: left; width: 200px; margin-right:15px;">
            <span class="input-group-addon">手机号码</span>
            <input type="text" class="form-control" id="search">
        </div>
        <div class="input-group" style="float: left; width: 200px; margin-right:15px;">
            <span class="input-group-addon">微信号</span>
            <input type="text" class="form-control" id="weixin">
        </div>
        <div class="input-group" style="float: left; width: 200px; margin-right:15px;">
            <span class="input-group-addon">支付宝号</span>
            <input type="text" class="form-control" id="alipay">
        </div>
        <div class="input-group" style="float: left; width: 200px; margin-right:15px;">
            <span class="input-group-addon">用户id</span>
            <input type="text" class="form-control" id="memberId">
        </div>
        <span onclick="search()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>
        <div class="btn-group">
            <button class="layui-btn " onclick="dx()">
                <i class="layui-icon">&#xe608;</i> 重置短信验证码次数
            </button>

            <button class="layui-btn" onclick="ye()">
                <i class="layui-icon">&#xe608;</i> 用户余额负数修正
            </button>

            <button class="layui-btn" onclick="jt()">
                <i class="layui-icon">&#xe608;</i> 截图任务新手任务未完成
            </button>

            <button class="layui-btn" onclick="newhandFinish()">
                <i class="layui-icon">&#xe608;</i> 每日必赚新手任务未完成
            </button>

<#--            <button class="layui-btn" onclick="negativeMoney()">
                <i class="layui-icon">&#xe608;</i> 负数修正
            </button>-->

        </div>


    </div>


    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

<style>
    .lay-box {
        padding: 8px 12px;
    }

    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }

</style>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="xbls">查看明细</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="delStatus">取消异常用户</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="wx">解绑微信</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="sfz">身份证信息修改</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="deleteAliMark">解除修改信息限制</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="setStatus">设为异常用户</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="closeMember">禁止登陆</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="cleanLoginRecord">清除当日设备登录记录</a>
</script>
<script type="text/html" id="barDemo1">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="select">查看每日必赚次数</a>
</script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.enable== 1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    var startDate = "";
    var endDate = "";
    var searchKey = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "tb_member";
    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        form.render();
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/member/data'
            ,
            method: 'POST'
            ,
            where: {
                query: {},
                key: {'': ''}
            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {type: 'checkbox', field: 'id'}
                ,
                {
                    field: 'gmt_created', title: '注册时间', templet: function (data) {
                        return dateFormat(data.createTime);
                    }, align: 'center', width: 160, sort: true
                }
                , {
                    field: 'phone',
                    title: '手机号',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'money',
                    title: '余额',
                    width: 100,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return (data.money / 100);
                    }
                }
                , {
                    field: 'hasDeleted',
                    title: '是否删除',
                    width: 110,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'inviteCode',
                    title: '邀请码',
                    width: 130,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'memberId',
                    title: '会员id',
                    width: 130,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'category',
                    title: '用户类型',
                    width: 130,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'status',
                    title: '用户状态',
                    width: 130,
                    align: 'center',
                    sort: true
                }


                , {
                    field: 'appStore',
                    title: '应用市场',
                    width: 130,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'brand',
                    title: '用户渠道',
                    width: 130,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'imei',
                    title: '设备号',
                    width: 130,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'successCount',
                    title: '提现成功',
                    width: 130,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'failCount',
                    title: '提现失败',
                    width: 130,
                    align: 'center',
                    sort: true
                }

                , {
                    field: 'redisMoney',
                    title: '缓存余额',
                    width: 130,
                    align: 'center',
                    sort: true
                }, {
                    field: 'allMoney',
                    title: '总收益',
                    width: 130,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return (data.allMoney / 100);
                    }
                }


                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 800,height:200, align: 'center'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo1', width: 320,height:200, align: 'center'}
            ]]
            ,
            page: true
        });

        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 1);
            } else {
                commonenable(this.value, 0);
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/sys/tbmember/delete",
                    type: 'post',
                    data: { "id": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'setStatus') {
                //设为异常用户
                $.ajax({
                    url: "/member/status",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: {'memberId': data.memberId, 'status': 1},
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        //请求成功时处理
                        alert(req.message)
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });
            } else if (obj.event === 'deleteAliMark') {
                //解除修改信息限制
                layer.confirm('确认解除限制?', function(index){

                    $.ajax({
                        url: "/member/deleteAliMark",    //请求的url地址
                        dataType: "json",   //返回格式为json
                        async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                        data: {'memberId': data.memberId},
                        type: "post",   //请求方式
                        beforeSend: function () {
                            //请求前的处理
                        },
                        success: function (req) {
                            //请求成功时处理

                            alert(req.message)
                        },
                        complete: function () {
                            //请求完成的处理
                        },
                        error: function () {
                            //请求出错处理
                            layer.msg("请重试！若在失败请联系管理员")
                        }
                    });

                    layer.close(index);
                });
            } else if (obj.event === 'xbls') {
                //查看明细
                var id = 'trade_list';
                var title = '收支明细';
                var href = '/sys/membernewtrade/list?memberId=' + data.memberId;
                if (id) {
                    window.parent.iw.open({
                        id: id,
                        title: title,
                        href: href
                    });
                }
            }else if(obj.event === 'closeMember'){
                //禁止登陆
                $.ajax({
                    url: "/member/closeMemberstatus",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: {'id': data.id},
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        //请求成功时处理

                        alert(req.message)
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });
            }else if(obj.event === 'sfz'){
               //身份证信息修改
                layer_show('身份证信息修改','/member/records/sfz?memberId='+data.memberId,'500','500')
            }else if(obj.event === 'wx'){
                //解绑微信
                $.ajax({
                    url: "/weixin/cancel",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: {'memberId': data.memberId},
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        //请求成功时处理
                        alert(req.message)
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });
            }else if(obj.event === 'delStatus'){
                //取消异常用户
                $.ajax({
                    url: "/member/status",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: {'memberId': data.memberId, 'status': 0},
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        //请求成功时处理

                        alert(req.message)
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });
            }else if(obj.event === 'delcount'){
                //取消异常用户
                $.ajax({
                    url: "/member/cleanmemberearncount",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                    data: {'memberId': data.memberId},
                    type: "post",   //请求方式
                    beforeSend: function () {
                        //请求前的处理
                    },
                    success: function (req) {
                        //请求成功时处理

                        layer.msg(req.message)
                    },
                    complete: function () {
                        //请求完成的处理
                    },
                    error: function () {
                        //请求出错处理
                        layer.msg("请重试！若在失败请联系管理员")
                    }
                });
            }else if(obj.event === 'select'){
                layer_show('用户每日必赚详情','/member/selectmemberearncount?memberId='+data.memberId,1050,750)
            }else if(obj.event === 'cleanLoginRecord'){
                //清除当日设备登录的记录
                layer_show('清除当日设备登录记录','/member/imeiloginrecord?memberId='+data.memberId,'500','500')
            }
        });
    });

    function search() {

        tableIns.reload('dataTableId', {
            where: {
                search:$("#search").val(),
                weixin:$("#weixin").val(),
                alipay:$("#alipay").val(),
                appId:$("#appId").val(),
                memberId:$("#memberId").val()

            }
            , page: {}
        });
    }



    function gradeEdit() {
        layer_show("新增", "/sys/tbmember/add", "650", "600");
    }

    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status) {
        $.ajax({
            url: "/common/commonSwitch",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": "has_deleted"},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }

    function postUrl(data,url) {
        $.ajax({
            url: url,    //请求的url地址
            dataType: "json",   //返回格式为json
            async: true,//请求是否异步，默认为异步，这也是ajax重要特性
            data: data,
            type: "get",   //请求方式

            success: function (req) {
                //请求成功时处理
                layer.msg(req.message)
            },
            error: function () {
                //请求出错处理
                layer.msg("请重试！若在失败请联系管理员")
            }
        });
    }

    function dx(){
        var phone=$("#search").val();
        postUrl({pa:"xmlb8888",phone:phone},"/member/clean/phone")
    }

    function ye(){
        var phone=$("#search").val();
        postUrl({pa:"xmlb8888",phone:phone},"/member/walletClean")
    }

    function jt(){
        var phone=$("#search").val();
        postUrl({pa:"xmlb8888",phone:phone},"/member/bull/phone")
    }

    function newhandFinish(){

        layer_show("新手任务每日必赚", "/member/dayearn", "650", "600");

    }

    function negativeMoney() {
        postUrl({pa:"xmlb8888"},"/member/updateNegativeMoney");
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
